package com.yao.config.demo;

import com.yao.config.Config;
import com.yao.config.exception.ConfigException;
import com.yao.config.exception.ConfigPathException;
import com.yao.config.tool.SimpleConfigManager;

/**
 * DEMO
 * 
 * @author YaoMing
 */
public class ConfigDemo {

	public static void main(String[] args) throws ConfigException, ConfigPathException {

		Config cf = new Config("classpath:com/yao/config/demo/config.xml");

		SimpleConfigManager.init("classpath:com/yao/config/demo/config.xml");
		cf = SimpleConfigManager.getConfig();
		// 与上面的效果一样，只不过做了全局变量，调用方便。

		System.out.println(cf.getString("yaoming.sex"));
		System.out.println(cf.getInteger("yaoming.age"));
		System.out.println(cf.getString("yaoming.wife"));
		System.out.println(cf.getString("yaoming.wife.son"));
		System.out.println(cf.getString("yaoming.blog"));

		// 保存功能
		cf.setValue("yaoming.wife", "goodgirl");
		cf.setValue("yaoming.age", "25");
		cf.saveAndReload();

		System.out.println(cf.getString("yaoming.wife"));
		System.out.println(cf.getString("yaoming.age"));

		System.out.println(cf.getString("tw.sex"));
		System.out.println(cf.getString("tw.age"));

	}
}
